package com.laoniu.controller.base;

import com.laoniu.annotation.OperateLog;
import com.laoniu.biz.base.BaseGoodsBiz;
import com.laoniu.dto.RestResult;
import com.laoniu.dto.request.BaseGoodsRequestDto;
import com.laoniu.dto.response.BaseGoodsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品信息表 前端控制器
 * </p>
 *
 * @author lxl
 * @since 2023-12-17
 */
@RestController
@RequestMapping("/base/goods")
public class BaseGoodsController {

    @Autowired
    private BaseGoodsBiz goodsBiz;

    /**
     * 分页查询商品
     * @param requestDto
     * @return
     */
    @PostMapping("list")
    public RestResult list(@RequestBody BaseGoodsRequestDto requestDto){
        return RestResult.success(goodsBiz.listPage(requestDto));
    }

    /**
     * 添加商品
     * @param dto
     * @return
     */
    @PostMapping("add")
    @OperateLog(bizName = "商品管理", operateType = "添加商品", operateDesc = "后台添加商品")
    public RestResult add(@RequestBody BaseGoodsDto dto){
        goodsBiz.addGoods(dto);
        return RestResult.success();
    }

    /**
     * 修改商品
     * @param dto
     * @return
     */
    @PostMapping("update")
    @OperateLog(bizName = "商品管理", operateType = "修改商品", operateDesc = "后台修改商品")
    public RestResult update(@RequestBody BaseGoodsDto dto){
        goodsBiz.updateGoods(dto);
        return RestResult.success();
    }

    /**
     * 删除商品
     * @param dto
     * @return
     */
    @PostMapping("delete")
    @OperateLog(bizName = "商品管理", operateType = "删除商品", operateDesc = "后台删除商品")
    public RestResult delete(@RequestBody BaseGoodsDto dto){
        return goodsBiz.delete(dto.getId());
    }

    /**
     * 查询所有商品
     * @return
     */
    @PostMapping("goodsBySupplier")
    public RestResult goodsBySupplier(@RequestBody BaseGoodsRequestDto dto){
        return RestResult.success(goodsBiz.goodsBySupplier(dto.getSupplier()));
    }
}
